package com.zaicheng.cloud.remotecall;

import com.zaicheng.cloud.netty.RpcRequest;

/**
 @author zaicheng
 @version 1.0
 @date 2022-04-19
 @email zzc15847256473@163.com
 */

public interface Target<T> {

        Class<T> type();

        String name();

        String url();

        RpcRequest apply(RequestTemplate requestTemplate);

        public  static  class  RemoteCallTarget<T> implements Target<T>{

            private final Class<T> type;
            private final String name;
            private final String  url;

            public RemoteCallTarget(Class<T> type, String url) {
                this(type,url,url);
            }

            public RemoteCallTarget(Class<T> type, String name, String url) {
                this.type = type;
                this.name = name;
                this.url = url;
            }

            @Override
            public Class<T> type() {
                return this.type;
            }

            @Override
            public String name() {
                return this.name;
            }

            @Override
            public String url() {
                return this.url;
            }

            @Override
            public RpcRequest apply(RequestTemplate requestTemplate) {
                 return  requestTemplate.request();
            }
        }
}
